package com.fieldchain.ex.fa100.ui.trade.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.fieldchain.ex.fa100.R;
import com.fieldchain.ex.fa100.bean.EntiustBean;
import java.util.ArrayList;
import java.util.List;
import com.fieldchain.ex.fa100.utils.common.TimeUtils;
import com.fieldchain.ex.fa100.utils.string.NumberFormate;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/9/13
 */
public class TradHistoryAdapter extends RecyclerView.Adapter<TradHistoryAdapter.ViewHolder> {
    private Context mContext;
    private int c1,c2;
    private String []str={"","交易中","已成交","已撤销","撤销申请中"};
    public TradHistoryAdapter(Context mContext) {
        this.mContext = mContext;
        c1= Color.parseColor("#FF00B05F");
        c2= Color.parseColor("#FFDC3950");
    }

    private List<EntiustBean> list = new ArrayList<>();

    public void setData(List<EntiustBean> list) {
        this.list.clear();
        this.list.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_trad_history, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        EntiustBean bean = list.get(position);
        String[] tags = bean.getMarket().split("_");
        String coin = tags[1];
        String company = tags[0];

        holder.tvTime.setText(TimeUtils.getSimpleTime2(bean.getCreateTime() + ""));
        holder.tvCompany.setText(company.toUpperCase());
        holder.tvCompany2.setText(coin.toUpperCase());
        holder.tvNum1.setText(NumberFormate.m5(bean.getPrice()));
        holder.tvNum2.setText(NumberFormate.m2(bean.getEntrustNumber()));
        holder.tvNum3.setText(NumberFormate.m2(bean.getTradeNumber()));
        holder.tvStatus.setText(str[bean.getStatus()]);

        if(bean.getDealType().equals("1")){
            holder.tvNum1.setTextColor(c2);
            holder.tvTags1.setTextColor(c2);
            holder.tvCompany2.setTextColor(c2);
        }else{
            holder.tvNum1.setTextColor(c1);
            holder.tvTags1.setTextColor(c1);
            holder.tvCompany2.setTextColor(c1);
        }


    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private LinearLayout linItem;
        private TextView tvStatus;
        private TextView tvTime;
        private TextView tvCompany;
        private TextView tvTags1;
        private TextView tvNum1;
        private TextView tvCompany2;
        private TextView tvNum2;
        private TextView tvNum3;
        public ViewHolder(View itemView) {
            super(itemView);
            linItem = itemView.findViewById(R.id.lin_item);
            tvStatus = itemView.findViewById(R.id.tv_status);
            tvTime = itemView.findViewById(R.id.tv_time);
            tvCompany = itemView.findViewById(R.id.tv_company);
            tvTags1 = itemView.findViewById(R.id.tv_tags1);
            tvNum1 = itemView.findViewById(R.id.tv_num1);
            tvCompany2 = itemView.findViewById(R.id.tv_company2);
            tvNum2 = itemView.findViewById(R.id.tv_num2);
            tvNum3 = itemView.findViewById(R.id.tv_num3);
        }
    }
}
